package com.joking.springbootguava.controller;

import com.google.common.util.concurrent.RateLimiter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class TestController {

    private RateLimiter rateLimiter = RateLimiter.create(10);

    @GetMapping("/test")
    public String test() {
        if(!rateLimiter.tryAcquire(10)) {
            log.info("访问限制");
            return "访问限制";
        }
        log.info("正常返回");
        return "正常返回";
    }
}
